/*
 * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

 /* ScriptData
 SDName: Boss_Majordomo_Executus
 SD%Complete: 30
 SDComment: Correct spawning and Event NYI
 SDCategory: Molten Core
 EndScriptData */

#include "ScriptMgr.h"
#include "ScriptedCreature.h"

#define SAY_AGGRO           -1409003
#define SAY_SPAWN           -1409004
#define SAY_SLAY            -1409005
#define SAY_SPECIAL         -1409006
#define SAY_DEFEAT          -1409007

#define SAY_SUMMON_MAJ      -1409008
#define SAY_ARRIVAL1_RAG    -1409009
#define SAY_ARRIVAL2_MAJ    -1409010
#define SAY_ARRIVAL3_RAG    -1409011
#define SAY_ARRIVAL5_RAG    -1409012

#define SPAWN_RAG_X         838.51f
#define SPAWN_RAG_Y         -829.84f
#define SPAWN_RAG_Z         -232.00f
#define SPAWN_RAG_O         1.70f

#define SPELL_MAGIC_REFLECTION      20619
#define SPELL_DAMAGE_REFLECTION     21075

#define SPELL_BLASTWAVE             20229
#define SPELL_AEGIS                 20620                   //This is self casted whenever we are below 50%
#define SPELL_TELEPORT              20618
#define SPELL_SUMMON_RAGNAROS       19774

#define ENTRY_FLAMEWALKER_HEALER    11663
#define ENTRY_FLAMEWALKER_ELITE     11664


class boss_majordomo : public CreatureScript
{
public:
    boss_majordomo() : CreatureScript("boss_majordomo") { }

    struct boss_majordomoAI : public ScriptedAI
    {
        boss_majordomoAI(Creature* c) : ScriptedAI(c) {}

        uint32 MagicReflection_Timer;
        uint32 DamageReflection_Timer;
        uint32 Blastwave_Timer;

        void Reset()
        {
            MagicReflection_Timer = 30000;                     //Damage reflection first so we alternate
            DamageReflection_Timer = 15000;
            Blastwave_Timer = 10000;
        }

        void KilledUnit(Unit* /*victim*/)
        {
            if (rand() % 5)
                return;

            DoScriptText(SAY_SLAY, me);
        }

        void EnterCombat(Unit* /*who*/)
        {
            DoScriptText(SAY_AGGRO, me);
        }

        void UpdateAI(const uint32 diff)
        {
            if (!UpdateVictim())
                return;

            //Cast Ageis if less than 50% hp
            if (HealthBelowPct(50))
                DoCast(me, SPELL_AEGIS);

            //Blastwave_Timer
            if (Blastwave_Timer <= diff)
            {
                DoCastVictim(SPELL_BLASTWAVE);
                Blastwave_Timer = 10000;
            }
            else Blastwave_Timer -= diff;

            DoMeleeAttackIfReady();
        }
    };

    CreatureAI* GetAI(Creature* pCreature) const
    {
        return new boss_majordomoAI(pCreature);
    }

};

void AddSC_boss_majordomo()
{
    new boss_majordomo();
}

